// Copyright 2012 Sergio, Raul, Dorival. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// STL
#include <iostream>
#include <cmath>

// GemLab
#include "gemlab.h"

using std::cout;
using std::endl;
using GemLab::Vec_t;
using GemLab::Mat_t;
using GemLab::Array;
using GemLab::String;
using GemLab::Geo2name;
using GemLab::Geo2nvc;
using GemLab::Geo2gnd;
using GemLab::Geo2natc;
using GemLab::Geo2func;

int main(int argc, char **argv) try
{
    bool with_err = false;

    Array<GemLab::Block> blks(1);
    blks[0].Set (/*NDim*/2, /*Tag*/-1, /*NVert*/4,
                 0.0,  0.0, 0.0,
                 0.0, 15.0, 0.0,
                 0.0, 15.0, 8.0,
                 0.0,  0.0, 8.0,  -10.0,-11.0,-12.0,-13.0);
    blks[0].SetNx(5);  blks[0].SetNy(4);
    GemLab::SMesh mesh(/*NDim*/2);
    mesh.Generate (blks,/*O2*/false);

    int    line_tag   = -4;
    int    joint_tag  = -5;
    bool   find_neigh = true;
    bool   o2         = false;
    double tol        = 1e-5;
    Vec_t X0(2), X1(2);
    X0 <<  2., 8.; 
    X1 << 10., 0.;
    EnrichMeshBisect(&mesh, Array<Vec_t>(X0, X1), Array<int>(-6,-66), line_tag, joint_tag, o2, tol);
    mesh.WriteVTU ("mesh_enrich03");

    char const * extra = "plot([2,10],[8,0],'g-',lw=2)\n";
    mesh.WriteMPY ("mesh_enrich03",/*tags*/true, /*ids*/true, /*shared*/false, extra);
    mesh.WriteMSH ("mesh_enrich03");

    if (with_err) return 1;
    return 0;
}
GEMLAB_CATCH
